<template>
  <el-card>
    <div slot="header">添加账号</div>
    <el-table :data="tableData"
    ref="multipleTable"
     @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="管理员组"  prop="userGroup" width="120">
      </el-table-column>
      <el-table-column prop="account" label="用户" width="120"> </el-table-column>
        <el-table-column label="日期">
          <template slot-scope="scope">
            {{ scope.row.ctime | formatYMD }}
          </template>
        </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      class="mt20"
      background
      :current-page="currentPage"
      :page-sizes="[3, 5]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <div class="mt20">
      <el-button type="warning">批量删除</el-button>
      <el-button type="primary">取消选择</el-button>
    </div>
  </el-card>
</template>

<script>
import { getUserListReq } from "@/api/user";
export default {
  data() {
    return {
      // 分页
      currentPage: 1,
      pageSize: 3,
      total: 0,
      // 表格内容
      tableData: [],
      multipleSelection: [],
    };
  },
  methods: {
    // 获取数据函数
    async getData() {
      // 提取数据
      let currentPage = this.currentPage;
      let pageSize = this.pageSize;
      // 发送请求
      let res = await getUserListReq({
        currentPage,
        pageSize,
      });
      //解构数据
      let { data, total } = res.data;
      //数据赋值
      this.total = total;
      this.tableData = data;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 编辑
    handleEdit(index, row) {
      console.log(index, row);
    },
    // 删除
    handleDelete(index, row) {
      console.log(index, row);
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
  // 生命周期初始化调用函数
  created() {
    // console.log(tableData)
    this.getData();
  },
};
</script>

<style lang="scss" scoped>
</style>